﻿#pragma once
#include<locale.h>
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define HEAD L'蛇'
#define BODY L'●'
#define FOOD L'★'
#define WALL L'墙'
#define POS_X 24
#define POS_Y 5
//蛇的方向
enum DRECTION {
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};
//蛇的状态
enum GAME_STATUS {
	OK,
	KILL_BY_WALL,
	KILL_BY_SELF,
	END_NORMAL
};
//蛇身节点
typedef struct SnakeNode {
	int x;
	int y;
	struct SnakeNode* next;
}SnakeNode,* pSnakeNode;

//
typedef struct Snake {
	pSnakeNode _pSnake;
	pSnakeNode _pFood;
	enum DRECTION _dir;
	enum GAME_STATUS _status;
	int food_weight;
	int sorce;
	int sleep_time;
}snake,* psnake;
//定位光标位置
void SetPos(short x, short y);
//游戏的初始化
void GameStart(psnake ps);
//欢迎界面的打印
void WelcomeGame();
//打印游戏界面
void CreatMap();
//蛇身初始化
void InitSnake(psnake ps);
//创建食物
void CreatFood(psnake ps);
//运行游戏
void GameRun(psnake ps);
//判断下一个位置是否是食物
int NextIsFood(pSnakeNode pn, psnake ps);
//吃掉食物
void EatFood(pSnakeNode pn, psnake ps);
//没有食物
void NoFood(pSnakeNode pn, psnake ps);
//撞墙
void KillByWall(psnake ps);
//撞到自己
void KillBySelf(psnake ps);

//游戏结束
void GameEnd(psnake ps);